﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Data;
using ModuleDALCore;
using QUANLYCHAMCONG.BL.Entities;
using QUANLYCHAMCONG.DAO.Core;
using QUANLYCHAMCONG.BL.Entities.Security;

namespace QUANLYCHAMCONG.DAO.DAO.Security
{
   public class USERDAO:DALBase
    {
       USER user;
         private string _SpName;
        public string SpName
        {
            get { return "SpUSER"; }
            set { _SpName = value; }
        }
        public USERDAO()
        {
            OpenConnect();
        }
        public bool Insert(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user,1)) == 1);
            }
            catch
            {
                return false;
            }
        }
        public bool Update(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user,2)) == 1);
            }
            catch
            {
                return false;
            }
        }
        public bool Delete(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user,3)) == 1);
            }
            catch
            {
                return false;
            }
        }
        public DataTable SelectByPK(USER user)
        {
            try
            {
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user,4));
            }
            catch
            {
                return null;
            }
        }
        public DataTable SelectALL()
        {
            user = new USER();
            try
            {
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user,0));
            }
            catch
            {
                return null;
            }
        }
        public int GetID()
        {
            user = new USER();
            try
            {
                return DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user, 5), DBConnectionState.CloseOnExit);
            }
            catch
            {
                return 0;
            }
        }
        public bool IsAdmin(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user, 2)) == 1);
            }
            catch
            {
                return false;
            }
        }
        public bool ISExists(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user, 7)) == 1);
            }
            catch
            {
                return false;
            }
        }
        public DataTable IsDulicateUserName(USER user)
        {
            try
            {
                return DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user, 6));
            }
            catch
            {
                return null;
            }
        }
        public bool IsLogin(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user, 8)) == 1);
            }
            catch
            {
                return false;
            }
        }
        public bool Changepassword(USER user)
        {
            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(user, null), ConvertClassToArray.GetValues(user, 9)) == 1);
            }
            catch
            {
                return false;
            }
        }
    }
}
